package com.hydl.power.controller;

import com.hydl.power.aop.annotation.LogAnnotation;
import com.hydl.power.pojo.HomePpageData;
import com.hydl.power.pojo.Project;
import com.hydl.power.service.HomePpageDataService;
import com.hydl.power.service.ProjectService;
import com.hydl.power.utils.Resp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/homeppagedata")
@Api(value = "HomePpageDataController", tags = "首页数据(废弃)")
@CrossOrigin
public class HomePpageDataController {

    @Autowired
    private HomePpageDataService homePpageDataService;

    @Autowired
    private ProjectService projectService;


/*    @GetMapping("/queryHomepPageData")
    @ApiOperation(value="查询首页数据信息")
    public Resp queryHomePpageData(){
        List<Project> project = projectService.queryProjectAll();
        HomePpageData homePpageData = homePpageDataService.queryHomePpageDataAll();
        homePpageData.setLongitudeLatitude(project);
        return Resp.success(homePpageData);
    }*/

    //@LogAnnotation(module = "首页数据",description = "根据经纬度查询本项目下所有数据")
    @PostMapping("/queryHomePpageDataById")
    @ApiOperation(value="根据经纬度查询本项目下所有数据(废弃)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "longitudeLatitude", value = "经度",required = true,  dataType = "String",defaultValue = "113.6285"),
            @ApiImplicitParam(paramType = "query", name = "latitudeLatitude", value = "纬度",required = true,  dataType = "String",defaultValue = "34.7832"),
    })
    public Resp queryHomePpageDataById(String longitudeLatitude,String latitudeLatitude){
        String arr =homePpageDataService.querySumPt(longitudeLatitude,latitudeLatitude);
        HomePpageData homePpageData =homePpageDataService.queryHomePpageDataById(longitudeLatitude,latitudeLatitude);
        if(homePpageData==null){
            return Resp.success("该项目下未查询到数据",null);
        }
        if(longitudeLatitude.equals("113.622133") && latitudeLatitude.equals("34.777051")){
            homePpageData.setTotalfixedcapacity("6000");
        }else {
            homePpageData.setTotalfixedcapacity("0");
        }
        homePpageData.setPt(arr);
        return Resp.success(homePpageData);
    }


    //@LogAnnotation(module = "首页数据",description = "根据经纬度查询本项目下用电量")
    @PostMapping("/querydayElectricity")
    @ApiOperation(value="根据经纬度查询本项目下用电量(废弃)")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "longitudeLatitude", value = "经度",required = true,  dataType = "String",defaultValue = "113.6285"),
            @ApiImplicitParam(paramType = "query", name = "latitudeLatitude", value = "纬度",required = true,  dataType = "String",defaultValue = "34.7832"),
    })
    public Resp querydayElectricity(String longitudeLatitude,String latitudeLatitude){
        String dayElectricity= homePpageDataService.querydayElectricity(longitudeLatitude,latitudeLatitude);
        String weekElectricity=homePpageDataService.queryWeekElectricity(longitudeLatitude,latitudeLatitude);
        String monthElectricity=homePpageDataService.queryMonthElectricity(longitudeLatitude,latitudeLatitude);
        String sumElectricity=homePpageDataService.querySumElectricity(longitudeLatitude,latitudeLatitude);
        HomePpageData homePpageData=new HomePpageData();
        homePpageData.setDayElectricity(dayElectricity);
        homePpageData.setWeekElectricity(weekElectricity);
        homePpageData.setMonthElectricity(monthElectricity);
        homePpageData.setSumElectricity(sumElectricity);
        return Resp.success(homePpageData);
    }


}
